package com.tdkj.action.front.member.informationManagement;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import net.sf.json.JSONSerializer;
import net.sf.json.JsonConfig;
import net.sf.json.util.CycleDetectionStrategy;

import org.hibernate.Criteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.tdkj.action.BaseAction;
import com.tdkj.model.information.BeanBaseInfo;
import com.tdkj.model.information.BeanInfoModule;
import com.tdkj.model.information.BeanModuleColumn;
import com.tdkj.model.user.BeanUser;
import com.tdkj.service.information.IBeanBaseInfoService;
import com.tdkj.service.information.IBeanInfoModuleService;
import com.tdkj.util.JsonUtil;

public class RecruitmentAction  extends BaseAction{
	private Long id;
	private String mn;
	private String mt;
	private String cn;
	private String ct;
	private String title;
	private String resource;
	private String content;
	private Map<String,String>prop=new HashMap<String,String>();
	private BeanBaseInfo info;
	private IBeanInfoModuleService infoModuleService;
	private IBeanBaseInfoService baseInfoService;
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getMn() {
		return mn;
	}

	public void setMn(String mn) {
		this.mn = mn;
	}

	public String getMt() {
		return mt;
	}

	public void setMt(String mt) {
		this.mt = mt;
	}

	public String getCn() {
		return cn;
	}

	public void setCn(String cn) {
		this.cn = cn;
	}

	public String getCt() {
		return ct;
	}

	public void setCt(String ct) {
		this.ct = ct;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getResource() {
		return resource;
	}

	public void setResource(String resource) {
		this.resource = resource;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public Map<String, String> getProp() {
		return prop;
	}

	public void setProp(Map<String, String> prop) {
		this.prop = prop;
	}

	public BeanBaseInfo getInfo() {
		return info;
	}

	public void setInfo(BeanBaseInfo info) {
		this.info = info;
	}

	public IBeanBaseInfoService getBaseInfoService() {
		return baseInfoService;
	}

	@Resource
	public void setBaseInfoService(IBeanBaseInfoService baseInfoService) {
		this.baseInfoService = baseInfoService;
	}

	public IBeanInfoModuleService getInfoModuleService() {
		return infoModuleService;
	}
	@Resource
	public void setInfoModuleService(IBeanInfoModuleService infoModuleService) {
		this.infoModuleService = infoModuleService;
	}

	public String findResume() {
		// TODO Auto-generated method stub
		mt="9";
		ct="2";
		Criteria criteria = this.createCriteria(BeanBaseInfo.class)
		.add(Restrictions.eq("moduletype",mt))
		.add(Restrictions.eq("columntype",ct))
		.addOrder(Order.desc("createtime"));// 对状态进行排序
		this.queryByPage(criteria, "recruitmentAction!findResume.action", 10);
		return "list";
	}
	
	public String findRecruit() {
		// TODO Auto-generated method stub
		mt="9";
		ct="1";
		Criteria criteria = this.createCriteria(BeanBaseInfo.class)
		.add(Restrictions.eq("moduletype",mt))
		.add(Restrictions.eq("columntype",ct))
		.addOrder(Order.desc("createtime"));// 对状态进行排序
		this.queryByPage(criteria, "recruitmentAction!findRecruit.action", 10);
		return "list";
	}
	public String findAddPage(){
		BeanModuleColumn bean=infoModuleService.findModuleColumn("9",this.getCt());
		this.setCn(bean.getColumnname());
		this.setCt(bean.getColumntype());
		this.setMn(bean.getInforModule().getModulename());
		this.setMt(bean.getInforModule().getModuletype());
		if(this.getCt().equals("1")){
			return "recruit_add";
		}else{
			return "resume_add";
		}
	}
	public String findEditPage(){
		BeanModuleColumn bean=infoModuleService.findModuleColumn("9",this.getCt());
		this.setCn(bean.getColumnname());
		this.setCt(bean.getColumntype());
		this.setMn(bean.getInforModule().getModulename());
		this.setMt(bean.getInforModule().getModuletype());
		info=baseInfoService.findById(this.getId(), BeanBaseInfo.class);
		if(this.getCt().equals("1")){
			return "recruit_edit";
		}else{
			return "resume_edit";
		}
	}
	
	public String deleteInfo(){
		baseInfoService.delete(this.getId(), BeanBaseInfo.class);
		String ct=this.getCt();
		if(ct.equals("1")){
			return findRecruit();
		}else{
			return findResume();
		}
	}
	public String editInfo(){
		ct=this.getCt();
		id=this.getId();
		mt=this.getMt();
		BeanBaseInfo info=baseInfoService.findById(this.getId(), BeanBaseInfo.class);
		if(this.getTitle()!=null)info.setTitle(this.getTitle());
		if(this.getContent()!=null)info.setContent(this.getContent());
		if(this.getMn()!=null)info.setModulename(this.getMn());
		if(this.getMt()!=null)info.setModuletype(this.getMt());
		if(this.getCn()!=null)info.setColumnname(this.getCn());
		if(this.getCt()!=null)info.setColumntype(this.getCt());
		if(this.getResource()!=null)info.setResource(this.getResource());
		if(this.getProp()!=null){
			info.setProp(this.getProp());
		}
		BeanUser u=this.getCurrentUser();
		info.setUser(u);
		baseInfoService.save(info);
		if(ct.equals("1")){
			return findRecruit();
		}else{
			return findResume();
		}
	}
	//发布消息
	public String addInfo(){
		BeanBaseInfo info=new BeanBaseInfo();
		if(this.getTitle()==null&&this.getTitle().equals("")) {
			this.addFieldError("titleVlidate", "标题不能为空");
		}
		if(this.getTitle()!=null)info.setTitle(this.getTitle());
		if(this.getContent()!=null)info.setContent(this.getContent());
		if(this.getMn()!=null)info.setModulename(this.getMn());
		if(this.getMt()!=null)info.setModuletype(this.getMt());
		if(this.getCn()!=null)info.setColumnname(this.getCn());
		if(this.getCt()!=null)info.setColumntype(this.getCt());
		if(this.getProp()!=null)info.setResource(this.getResource());
		info.setCreatetime(new Timestamp(System.currentTimeMillis()));
		info.setClicktime(1);
		info.setStatus("未审核");
		if(this.getProp()!=null){
			info.setProp(this.getProp());
		}
		BeanUser u=this.getCurrentUser();
		info.setUser(u);
		baseInfoService.save(info);
		ct=this.getCt();
		return findAddPage();
	}
}
